package vj.math;

public class Power {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(power(5, 17));

	}
	
	/*
	 * a^b
	 */
	public static double power(int a, int b) {
		if(b == 0)
			return 1;
		if(b == 1)
			return a;
		if(b < 0) 
			return 1/power(a, -b);
		if(b % 2 == 0) {
			double r = power(a, b/2);
			return r * r;
		} else {
			double r = power(a, b/2);
			return r * r * a;
		}
	}

}
